package com.spit.fammo.adapter

import androidx.recyclerview.widget.DiffUtil
import com.spit.fammo.bean.db.AssetBean

/**
 * User: Nike
 *  2025/2/18 09:39
 */
class AssetDiffCallback(
    private val oldList: List<AssetBean>,
    private val newList: List<AssetBean>
) : DiffUtil.Callback() {

    override fun getOldListSize(): Int = oldList.size

    override fun getNewListSize(): Int = newList.size

    override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
        // 假设 AssetBean 的 id 是唯一标识符
        return oldList[oldItemPosition].uid == newList[newItemPosition].uid
    }

    override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
        val oldItem = oldList[oldItemPosition]
        val newItem = newList[newItemPosition]
        return oldItem == newItem
    }

    override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? {
        // 如果需要，可以返回一个载荷来帮助ViewHolder更新内容
        // 这在数据项更改但某些字段更改时很有用
        return super.getChangePayload(oldItemPosition, newItemPosition)
    }

}